#include <bits/stdc++.h>
using namespace std;

#define DEBUG
#ifdef DEBUG
#define TRG_PG(str, argv...) fprintf(stderr, "  TRC_PG(%s:%d):\t" str, __func__, __LINE__, ##argv)
#define debug fprintf(stderr, "DEBUG(%s:%d)\n", __func__, __LINE__)
#else
#define TRG_PG(str, argv...)
#define debug
#endif

const int MAX_N = 2e5 + 10;

int a[MAX_N];
int n;

void input()
{
    cin >> n;
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i];
    }
}

void work()
{
    long long ans = 0;
    for (int s = 0; s < (1 << n); s++)
    {
        long long cnt = 0;
        for (int i = 1; i <= n; i++)
        {
            int t = 0;
            for (int j = i - 1; j >= 1; j--)
            {
                if (((s >> (i - 1)) & 1) == ((s >> (j - 1)) & 1))
                {
                    t = j;
                    break;
                }
            }
            if (a[i] == a[t])
            {
                cnt += a[i];
            }
        }
        ans = max(ans, cnt);
    }
    cout << ans << "\n";
}

int main()
{
    freopen("color.in", "r", stdin);
    freopen("color.out", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);
    int T;
    cin >> T;
    while (T-- > 0)
    {
        input();
        work();
    }
    return 0;
}
